package com.snimmo.demo.weld.util;

import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.PersistenceContext;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ResourceFactory {
	
	@Produces
    public Logger produceLog(InjectionPoint injectionPoint) {
		return LoggerFactory.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
    }
	
	@Produces
    @PersistenceContext
	public EntityManager createEntityManager(){
		EntityManagerFactory emf = Persistence.createEntityManagerFactory("default");
		return emf.createEntityManager();
	}

}
